package com.ocm.commerceinteraction.ui;


import android.graphics.Bitmap;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.ocm.commerceinteraction.IndexActivity;
import com.ocm.commerceinteraction.R;
import com.ocm.commerceinteraction.util.view.ProgressWebView;
import com.ocm.commerceinteraction.util.view.percentsupport.PercentRelativeLayout;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;


@EFragment(R.layout.fragment_web)
public class ResetWebFragment extends BaseFragment {


    //    @ViewById(R.id.back_btn)
//    ImageButton backBtn;
//
    @ViewById(R.id.toptitle_title)
    TextView topTitle;
    //    @ViewById(R.id.recyclerview)
//    RecyclerView recyclerView;
//
    ResetWebFragment homeFragment;
    @ViewById(R.id.back_btn)
    PercentRelativeLayout backBtn;

    @ViewById(R.id.ad_webview)
    ProgressWebView adWebview;

    @AfterViews
    @Override
    void initView() {
        homeFragment = this;
        topTitle.setText("重置密码");
        backBtn.setVisibility(View.VISIBLE);
        loadData();

    }

    //加载数据
    private void loadData() {
        adWebview.getSettings().setJavaScriptEnabled(true);
        adWebview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
//              return super.shouldOverrideUrlLoading(view, url);
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);

            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);

            }

        });

        adWebview.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                return true;
            }
        });
        adWebview.addJavascriptInterface(this, "ocm");
        adWebview.loadUrl("http://bchat.ocmcom.com/HUser/resetpwd");
    }

    /**
     * js 跳转到登录界面
     */
    @JavascriptInterface
    public void show() {
        IndexActivity.getInstance().getSupportFragmentManager().popBackStack();
    }
    @Override
    @Click(R.id.back_btn)
    void Click(View view) {
        switch (view.getId()) {
            case R.id.back_btn:
                IndexActivity.getInstance().getFragmentManager().popBackStack();
                break;
        }
    }


}
